void main() {
  // Dart 的判断条件必须是布尔值，不能是其他类型
  if (true) {
    print("ok");
  }
//  fortest();
  whileTest();

  while (true) {
    if (shutDownRequested()) break;
    processIncomingRequests();
  }

  assert(false);
  print("测试assert中断");
}

void fortest() {
  var callbacks = [];
  for (var i = 0; i < 2; i++) {
    callbacks.add(() => print(i));
  }
  callbacks.forEach((c) => c());

  var collection = [0, 1, 2];
  for (var x in collection) {
    print(x); // 0 1 2
  }
}

void whileTest() {
  while (!isDone()) {
    doSomething();
  }
}

var i = 5;
bool isDone() {
  if (i > 0) {
    return false;
  }
  return true;
}

void doSomething() {
  i--;
  print(i);
}

bool shutDownRequested() {
  print("break");
  return true;
}

void processIncomingRequests() {
  print("ok");
}